package com.llkj.qingnianguoxue.adapter;

import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chauthai.swipereveallayout.SwipeRevealLayout;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.CircleListBean;
import com.llkj.qingnianguoxue.util.ClickViewCallback;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;
import com.llkj.qingnianguoxue.util.TextViewUtil;

import java.util.List;

/**
 * 圈子——我的圈子
 */
public class MyCircleAdapter extends BaseQuickAdapter<CircleListBean.CircleBean, BaseViewHolder> {
    private ClickViewCallback clickViewCallback;
    private int type = 1;//1兴趣，2我的,3搜索

    public MyCircleAdapter(int layoutResId, List<CircleListBean.CircleBean> data, ClickViewCallback listener) {
        super(layoutResId, data);
        clickViewCallback = listener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, CircleListBean.CircleBean item) {
        ImageLoadingUtil.loadingCircleBorderImg((ImageView) baseViewHolder.getView(R.id.iv_head), item.getImg(), R.color.transparent);
        baseViewHolder.setText(R.id.tv_name, item.getName());
//        baseViewHolder.setText(R.id.tv_add_circle, item.getName());
        baseViewHolder.setText(R.id.tv_introduction, item.getFans()+"人气");

        String price = "￥"+item.getPrice()+"元/"+item.getCycle()+"天";
        SpannableString spannableString = TextViewUtil.getForegroundColorSpan(mContext,price,0,price.length()-4, ContextCompat.getColor(mContext, R.color.colorFE4A49));
        baseViewHolder.setText(R.id.tv_price,spannableString);
        if(type==2){
            baseViewHolder.setVisible(R.id.tv_price,false);
            TextView tvName = baseViewHolder.getView(R.id.tv_name);
            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tvName.getLayoutParams();
            params.topMargin = DisplayUtil.dip2px(mContext,10);
        }

        TextView tvAddCircle = baseViewHolder.getView(R.id.tv_add_circle);
        ImageView ivGo = baseViewHolder.getView(R.id.tv_circle_right);

        ivGo.setVisibility(View.VISIBLE);
        tvAddCircle.setVisibility(View.GONE);

        SwipeRevealLayout swipeDelGroup = baseViewHolder.getView(R.id.swipeDelGroup);
        TextView tvDelItem = baseViewHolder.getView(R.id.tvDelItem);
        tvDelItem.getLayoutParams().height = DisplayUtil.dip2px(mContext, 80);
        baseViewHolder.addOnClickListener(R.id.tvDelItem);
        swipeDelGroup.close(true);
        swipeDelGroup.setSwipeListener(new SwipeRevealLayout.SimpleSwipeListener() {
            @Override
            public void onClosed(SwipeRevealLayout view) {
                super.onClosed(view);
            }

            @Override
            public void onOpened(SwipeRevealLayout view) {
                super.onOpened(view);
            }
        });
    }

    private void setClickListener(final View view, final int position) {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickViewCallback != null) {
                    clickViewCallback.clickViewCallback(position, 0, view);
                }
            }
        });
    }

    /**
     * 设置界面显示UI
     *
     * @param type1 1兴趣，2我的
     */
    public void setType(int type1) {
        type = type1;
    }
}
